package com.example.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.dto.UserDTO;
import com.example.demo.entity.Record;
import com.example.demo.common.Result;
import com.example.demo.mapper.RecordMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
@RequiredArgsConstructor
public class CompanyService {

    private final RecordMapper recordMapper;

    public Result getCompanyList(String title, String phone, String creater) {
        QueryWrapper<Record> wrapper = new QueryWrapper<>();
        wrapper.select("type", "module", "content");
        wrapper.eq("module", "家电维修查看页");
        //List<Record> list = recordMapper.selectList(wrapper);

        List<Map<String, Object>> list = recordMapper.selectMaps(wrapper);

        log.info("执行了");

        Result res = new Result();
        res.ok();
        //res.setInterceptError("出错了");
        res.put("list", list);
        return res;
    }

    public String getUserList(UserDTO userDTO) {
        Result res = new Result();
        res.ok();
        return res.toString();
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public String addUser() throws Exception {
        Record info = new Record() {{
            setRecordid("luohailinysyl-1");
            setContent("一首歌");
            setType("update");
            setModule("企业");
        }};
        recordMapper.insert(info);

        Record info2 = new Record() {{
            setRecordid("luohailinysyl-2");
            setContent("一部电影");
            setType("update");
            setModule("学校");
        }};
        recordMapper.insert(info2);

        String name = null;
        name.toString();

        Result res = new Result();
        res.ok();
        return res.toString();
    }

    public String editUser() {
        Record info = new Record() {{
            setRecordid("luohailinysyl-1");
            setContent("一首歌");
            setType("update");
            setModule("企业");
        }};
        recordMapper.insert(info);

        Record info2 = new Record() {{
            setRecordid("luohailinysyl-2");
            setContent("一部电影");
            setType("update");
            setModule("学校");
        }};
        recordMapper.insert(info2);

        String name = null;
        name.toString();

        Result res = new Result();
        res.ok();
        return res.toString();
    }
}
